package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocLowIncomeDao;
import com.irdstudio.cdp.pboc.service.domain.PbocLowIncome;
import com.irdstudio.cdp.pboc.service.facade.PbocLowIncomeService;
import com.irdstudio.cdp.pboc.service.vo.PbocLowIncomeVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 低保救助记录				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocLowIncomeService")
public class PbocLowIncomeServiceImpl implements PbocLowIncomeService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocLowIncomeServiceImpl.class);

	@Autowired
	private PbocLowIncomeDao pbocLowIncomeDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocLowIncome(PbocLowIncomeVO inPbocLowIncomeVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocLowIncomeVo.toString());
		int num = 0;
		try {
			PbocLowIncome pbocLowIncome = new PbocLowIncome();
			beanCopy(inPbocLowIncomeVo, pbocLowIncome);
			num = pbocLowIncomeDao.insertPbocLowIncome(pbocLowIncome);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocLowIncomeVO inPbocLowIncomeVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocLowIncomeVo);
		int num = 0;
		try {
			PbocLowIncome pbocLowIncome = new PbocLowIncome();
			beanCopy(inPbocLowIncomeVo, pbocLowIncome);
			num = pbocLowIncomeDao.deleteByPk(pbocLowIncome);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocLowIncomeVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocLowIncomeVO inPbocLowIncomeVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocLowIncomeVo.toString());
		int num = 0;
		try {
			PbocLowIncome pbocLowIncome = new PbocLowIncome();
			beanCopy(inPbocLowIncomeVo, pbocLowIncome);
			num = pbocLowIncomeDao.updateByPk(pbocLowIncome);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocLowIncomeVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocLowIncomeVO queryByPk(PbocLowIncomeVO inPbocLowIncomeVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocLowIncomeVo);
		try {
			PbocLowIncome queryPbocLowIncome = new PbocLowIncome();
			beanCopy(inPbocLowIncomeVo, queryPbocLowIncome);
			PbocLowIncome queryRslPbocLowIncome = pbocLowIncomeDao.queryByPk(queryPbocLowIncome);
			if (Objects.nonNull(queryRslPbocLowIncome)) {
				PbocLowIncomeVO outPbocLowIncomeVo = beanCopy(queryRslPbocLowIncome, new PbocLowIncomeVO());
				logger.debug("当前查询结果为:"+ outPbocLowIncomeVo.toString());
				return outPbocLowIncomeVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLowIncomeVO> queryAllOwner(PbocLowIncomeVO pbocLowIncomeVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocLowIncomeVO> list = null;
		try {
			List<PbocLowIncome> pbocLowIncomes = pbocLowIncomeDao.queryAllOwnerByPage(pbocLowIncomeVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocLowIncomes.size());
			pageSet(pbocLowIncomes, pbocLowIncomeVo);
			list = (List<PbocLowIncomeVO>) beansCopy(pbocLowIncomes, PbocLowIncomeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLowIncomeVO> queryAllCurrOrg(PbocLowIncomeVO pbocLowIncomeVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocLowIncome> pbocLowIncomes = pbocLowIncomeDao.queryAllCurrOrgByPage(pbocLowIncomeVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocLowIncomes.size());
		List<PbocLowIncomeVO> list = null;
		try {
			pageSet(pbocLowIncomes, pbocLowIncomeVo);
			list = (List<PbocLowIncomeVO>) beansCopy(pbocLowIncomes, PbocLowIncomeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocLowIncomeVO> queryAllCurrDownOrg(PbocLowIncomeVO pbocLowIncomeVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocLowIncome> pbocLowIncomes = pbocLowIncomeDao.queryAllCurrDownOrgByPage(pbocLowIncomeVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocLowIncomes.size());
		List<PbocLowIncomeVO> list = null;
		try {
			pageSet(pbocLowIncomes, pbocLowIncomeVo);
			list = (List<PbocLowIncomeVO>) beansCopy(pbocLowIncomes, PbocLowIncomeVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
